﻿/***************************************V4.0兼容以前***********************************************/
function GetFullWH() {
    var opt = { w: 0, h: 0 }
    opt.w = (window.innerWidth) ? window.innerWidth : (window.document.documentElement && window.document.documentElement.clientWidth) ? window.document.documentElement.clientWidth : window.document.body.offsetWidth;
    opt.h = (window.innerHeight) ? window.innerHeight : (window.document.documentElement && window.document.documentElement.clientHeight) ? window.document.documentElement.clientHeight : window.document.body.offsetHeight;
    return opt;
}
//url, data, success, async
function TOPAjax(options) {

    if (options.async == undefined) options.async = true;
    if (!options.timeout) options.timeout = 120000;
    top.$.ajax({
        url: options.url,
        type: "POST",
        dataType: 'json',
        async: options.async,
        data: options.data,
        success: function (r) {
            if (r.code == "-999" || r.code == "-998") {
                ReLogin();
            }
            else {
                options.success(r);
            }
        },
        timeout: options.timeout,
        cache: false,
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            if (options.Alert) {
                kendo.message("运行错误！" + textStatus + " " + errorThrown);
            }
            else {

            }

            {
                options.success({ code: "-1", Errors: "运行错误", Data: [] });
            }

        }
    });
}
function MsgBox(msg, type) {
    var win = window;
    if (win.$("#popupNotification").length == 0) {
        win.$("body").append("<div id='popupNotification' />");
    }

    if (!win.$("#popupNotification").data("kendoNotification")) {
        win.$("#popupNotification").kendoNotification({
            position: {
                pinned: true,
                buttom: 10,
                right: 5
            },
            height: 50,
            width: 150,
            autoHideAfter: 3000,
            stacking: "up",
            templates: [
                {
                    type: "info",
                    template: '<div class="popupNotification"><table><tr><td><img src="/images/envelope.png" /></td><td>#= message #</td></tr></table></div>'
                },
                {
                    type: "error",
                    template: '<div class="popupNotification"><table><tr><td><img src="/images/error-icon.png" /></td><td>#= message #</td></tr></table></div>'
                },
                {
                    type: "success",
                    template: '<div class="popupNotification"><table><tr><td><img src="/images/success-icon.png" /></td><td>#= message #</td></tr></table></div>'
                }
            ]

        }).data("kendoNotification");
    }
    var popupNotification = win.$("#popupNotification").data("kendoNotification");
    if (!type) type = "info";
    popupNotification.show(
        { message: msg },
        type
    );
    $(".k-animation-container").css("z-index", GetMaxZ_index() + 1);
}
function ShowInfo(msg) {
    MsgBox(msg, "info");
}
function ShowError(msg) {
    MsgBox(msg, "error");
}
function ShowSuccess(msg) {
    MsgBox(msg, "success");
}
function TOPShowInfo(msg) {
    top.ShowInfo(msg, "info");
}
function TOPShowError(msg, title, option, fun) {
    if (title == null || title == "") {
        title = "错误提示"
    }
    var $ = kendo.jQuery;
    var _kendoMessage;
    var _kendoMessageDom;
    var defaultOption = {
        width: "400px", height: "150px", title: title, actions: ["Close"], modal: true,
        button: {
            text: '&nbsp&nbsp关闭&nbsp&nbsp', callback: function (f, kendoMessage) {
                if (f && typeof (f) == "function") { f() };
                kendoMessage.close();
            }
        }
    };
    $.extend(defaultOption, option);

    var html = '<div><div id="msg" style="height: 60%;margin:8px;overflow:hidden;" >' + msg + '</div>' +
        '<div class="k-edit-buttons k-state-default k-window-action" style="text-align:center;margin: 8px;">' +
        '<a href="#" class="k-button">' + defaultOption.button.text + '</a></div></div>';
    _kendoMessageDom = top.$(html);
    _kendoMessageDom.kendoWindow(defaultOption);
    _kendoMessage = _kendoMessageDom.data("kendoWindow");
    _kendoMessage.center();
    _kendoMessage.open();
    _kendoMessageDom.find("a").click(function () { defaultOption.button.callback(fun, _kendoMessage); });
}
function TOPShowSuccess(msg) {
    top.ShowSuccess(msg, "success");
}
function GetMaxZ_index() {
    var maxZ = Math.max.apply(null, $.map($('body > *'), function (e, n) {
        if ($(e).css('position') == 'absolute')
            return parseInt($(e).css('z-index')) || 1;
    })
    );
    return maxZ;
}


function ListIndex(l, v, field) {
    if (!field) field = "id";
    for (i = 0; i < l.length; i++) {
        if (l[i].id == v) {
            return i;
        }
    }
    return -1;
}
function kendoWindowIframeOpen(opt) {
    var win = window;
    if (opt.content == null) {
        opt.content = opt.url;
    }
    var baseoption = {
        "ID": "1",
        "visible": false,
        "modal": true,
        "iframe": true,
        "draggable": true,
        "pinned": false,
        "animation": false,
        "title": "系统提示",
        "resizable": false,
        "content": "空",
        "width": 400,
        "height": 300,
        "actions": ["Refresh", "Close"]
    };
    if (opt.close) {
        opt.DOClose = opt.close;
        opt.close = undefined;
    }
    var option = $.extend({}, baseoption, opt);

    if (opt.isMax) {
        var size = GetFullWH();
        option.height = size.h - 35;
        option.width = size.w - 10;
    }
    else if (opt.isMaxH) {
        var size = GetFullWH();
        option.height = size.h - 60;
    }
    else if (opt.isMaxW) {
        var size = GetFullWH();
        option.width = size.w - 60;
    }

    var id = Math.random().toString().substr(2);
    var w = win.$('<div id="' + id + '"/>').kendoWindow(option).data("kendoWindow");

    kendo.ui.progress(win.$("#" + id), true);

    w.wrapper.find("iframe")[0].onload = w.wrapper.find("iframe")[0].onreadystatechange = function () {
        if (this.readyState && this.readyState != 'complete') return;
        else {
            kendo.ui.progress(win.$("#" + id), false);

        }
    }

    w.bind("refresh", function () {
        w.wrapper.find("iframe")[0].contentWindow.SelfClose = function (args) {
            if (args) {
                if (opt.success) {
                    try {
                        opt.success(args);
                    }
                    catch (Error) {
                    }
                }
            }
            w.close();
        }
        if (option.onload) {
            option.onload(w.wrapper.find("iframe")[0].contentWindow);
        }
    });
    w.bind("close", function () {
        if (opt.DOClose) {
            opt.DOClose(w.wrapper.find("iframe")[0].contentWindow);//初始化事件
        }

        var f = w.wrapper.find("iframe")[0];
        f.contentWindow.document.write('');
        f.contentWindow.close();
        f.parentNode.removeChild(f);
    });
    if (option.left) {
        w.open();
    }
    else {
        w.center().open();
    }
    

}

//opt :title,url,width,height,success
function TOPkendoWindowIframeOpen(opt) {
    top.kendoWindowIframeOpen(opt);
}

function ReLogin() {

    top.LogOut();
    //top.window.location = '/home/logout';
    return;
    TOPkendoWindowIframeOpen({
        title: "登录"
        , url: "/Home/Login"
        , width: 350
        , height: 250
        , success: function (r) {
        }
    });
}
var ServerList = [
    { id: "TESTDB", text: "测试" }
    ,
    { id: "DXDB", text: "成都" },
    { id: "DWDB", text: "东莞" }
];

var EMPTYGUID = '00000000-0000-0000-0000-000000000000';

function IFrameOpen(fobjid, url) {

    var progressid = $("#" + fobjid).parent();
    IFrameProcess(fobjid, progressid);

    kendo.ui.progress(progressid, true);
    try {

        var f = $("#" + fobjid)[0];
        f.contentWindow.document.write('');
        f.contentWindow.close();
        //f.parentNode.removeChild(f);         
    }
    catch (Error) { }
    $("#" + fobjid).attr("src", url);


}
function IFrameProcess(fobjid, progressid) {

    var fobj = document.getElementById(fobjid);
    fobj.onload = fobj.onreadystatechange = function () {
        if (this.readyState && this.readyState != 'complete') return;
        else {
            kendo.ui.progress(progressid, false);
        }
    }

}
String.format = function () {
    if (arguments.length == 0) {
        return null;
    }
    var str = arguments[0];
    for (var i = 1; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

String.prototype.replaceAll = stringReplaceAll;

function stringReplaceAll(AFindText, ARepText) {
    raRegExp = new RegExp(AFindText, "g");
    return this.replace(raRegExp, ARepText)
}



function guid() {
    function S4() {
        return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
    }
    return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4() + S4() + S4());
}
EMPTYSELECT = '--请选择--';

function CloseWindow() {
    top.window.opener = null;
    top.window.open('', '_self');
    top.window.close();
}

function GetGridSelectData(gid) {
    if (!gid) gid = "grid";
    var grid = $("#" + gid).data("kendoGrid");
    var row = grid.select();
    if (!row) {
        return null;
    }
    var data = grid.dataItem(row);
    if (!data) {
        return null;
    }
    return data;
}


function SVGsupported() {
    if (SVG && SVG.supported) {
        return true;
    }
    else {
        $("body").html("你的浏览器不支持SVG1，\
        请<a href='http://www.adobe.com/devnet/svg/adobe-svg-viewer-download-area.html' target='_blank'>下载</a>插件 ");
        return false;
    }
}
function MidImg(obj) {
    var url = $(obj).attr("src");
    TOPkendoWindowIframeOpen({
        title: "图片"
        , url: "/sys/Image/ShowBigImg?url=" + escape(url)
        , isMax: false
        , width: 1024
        , height: 700
        , success: function (r) {
        }
    });
}
function ShowBigImg(url, title) {
    if (!title) {
        title = "图片";
    }
    TOPkendoWindowIframeOpen({
        title: title
        , url: "/sys/Image/ShowBigImg?url=" + url
        , isMax: true
        , success: function (r) {
        }
    });
}
function YXM_getEvent() {
    if (document.all) return window.event;
    YXM_func = YXM_getEvent.caller;
    while (YXM_func != null) {
        var YXM_arg0 = YXM_func.arguments[0];
        if (YXM_arg0) {
            if ((YXM_arg0.constructor == Event || YXM_arg0.constructor == MouseEvent) || (typeof (YXM_arg0) == "object" && YXM_arg0.preventDefault && YXM_arg0.stopPropagation)) { return YXM_arg0; }
        }
        YXM_func = YXM_func.caller;
    }
    return null;
}
function stopDefault(e) {
    if (e && e.preventDefault) {
        e.preventDefault();
    } else {
        YXM_getEvent().returnValue = false;
    }
    return false;
}
function InputDialog(opt) {
    var baseoption = {
        width: 400,
        height: 200,
        defaultValue: "",
        prompt: "请录入信息",
        title: "录入对话框"
    };

    var option = $.extend({}, baseoption, opt);
    TOPkendoWindowIframeOpen({
        title: option.title
        , url: "/sys/dialog/input?prompt=" + escape(option.prompt) + "&defaultvalue=" + escape(option.defaultValue)
        , width: option.width
        , height: option.height
        , success: function (r) {
            opt.success(r);
        }
    });
}
function TextAreaDialog(opt) {
    var baseoption = {
        width: 400,
        height: 200,
        defaultValue: "",
        prompt: "请录入信息",
        title: "录入对话框"
    };

    var option = $.extend({}, baseoption, opt);
    TOPkendoWindowIframeOpen({
        title: option.title
        , url: "/sys/dialog/TextArea?prompt=" + escape(option.prompt) + "&defaultvalue=" + escape(option.defaultValue)
        , width: option.width
        , height: option.height
        , success: function (r) {
            opt.success(r);
        }
    });
}
function TextAreaDialog(opt) {
    var baseoption = {
        width: 400,
        height: 200,
        defaultValue: "",
        prompt: "请录入信息",
        title: "录入对话框"
    };

    var option = $.extend({}, baseoption, opt);
    TOPkendoWindowIframeOpen({
        title: option.title
        , url: "/sys/dialog/TextArea?prompt=" + escape(option.prompt) + "&defaultvalue=" + escape(option.defaultValue)
        , width: option.width
        , height: option.height
        , success: function (r) {
            opt.success(r);
        }
    });
}
function CheckboxDialog(opt) {
    var baseoption = {
        width: 300,
        height: 400,
        Multiselect: "0",
        defaultValue: "",
        prompt: "请选择",
        title: "选择对话框",
        data: [{ ID: "1", Name: "是" }, { ID: "2", Name: "否" }]
    };

    var option = $.extend(true, {}, baseoption, opt);
    TOPkendoWindowIframeOpen({
        title: option.title
        , url: "/sys/dialog/CheckBox?DefaultValue=" + escape(option.defaultValue) + "&Multiselect=" + option.Multiselect
        , width: option.width
        , height: option.height
        , onload: function (win) {
            win.SetData(option.data);
        }
        , success: function (r) {
            opt.success(r);
        }
    });
}
function CheckboxDialogNoData(opt) {
    var baseoption = {
        width: 300,
        height: 400,
        Multiselect: "0",
        defaultValue: "",
        prompt: "请选择",
        title: "选择对话框",
        data: []
    };

    var option = $.extend(true, {}, baseoption, opt);
    TOPkendoWindowIframeOpen({
        title: option.title
        , url: "/sys/dialog/CheckBoxFW?DefaultValue=" + escape(option.defaultValue) + "&Multiselect=" + option.Multiselect
        , width: option.width
        , height: option.height
        , onload: function (win) {
            win.SetData(option.data);
        }
        , success: function (r) {
            opt.success(r);
        }
    });
}
(function (kendo) {
    kendo.message = function (newMessage, option, fun) {
        var $ = kendo.jQuery;
        var _kendoMessage;
        var _kendoMessageDom;
        var defaultOption = {
            width: "400px", height: "150px", title: "消息", actions: ["Close"], modal: true,
            button: {
                text: '&nbsp&nbsp确定&nbsp&nbsp', callback: function (f, kendoMessage) {
                    if (f && typeof (f) == "function") { f() };
                    kendoMessage.close();
                }
            }
        };
        $.extend(defaultOption, option);

        var html = '<div><div id="msg" style="height: 60%;margin:8px;overflow:hidden;" >' + newMessage + '</div>' +
            '<div class="k-edit-buttons k-state-default k-window-action" style="text-align:center;margin: 8px;">' +
            '<a href="#" class="k-button">' + defaultOption.button.text + '</a></div></div>';
        _kendoMessageDom = top.$(html);
        _kendoMessageDom.kendoWindow(defaultOption);
        _kendoMessage = _kendoMessageDom.data("kendoWindow");
        _kendoMessage.center();
        _kendoMessage.open();
        _kendoMessageDom.find("a").click(function () { defaultOption.button.callback(fun, _kendoMessage); });


    },
        kendo.confirm = function (newConfirm, option, fun, funno) {
            var $ = kendo.jQuery;
            var defaultOption = {
                width: "400px",
                height: "150px",
                title: "删除确认",
                resizable: false,
                actions: [
                    "Close"
                ],
                modal: true,
                ok: {
                    text: '&nbsp&nbsp确定&nbsp&nbsp',
                    callback: function (f, kendoConfirm) {
                        if (f && typeof (f) == "function") { f() };
                        kendoConfirm.close()
                    }
                },
                cancel: {
                    text: '&nbsp&nbsp取消&nbsp&nbsp',
                    callback: function (n, kendoConfirm) {
                        if (n && typeof (n) == "function") { n() };
                        kendoConfirm.close()
                    }
                }
            };
            defaultOption = $.extend(true, {}, defaultOption, option);

            var html = '<div><div id="msg" style="height: 60%;margin:8px;overflow:hidden;" >' + newConfirm + '</div>' +
                '<div class="k-edit-buttons k-state-default k-window-action" style="text-align:center;margin: 8px;">' +
                '<a href="#" class="k-button" id="confirmOk" style="margin-right:8px;">' + defaultOption.ok.text + '</a>' +
                '<a href="#" class="k-button" id="confirmCancel">' + defaultOption.cancel.text + '</a></div></div>';
            _kendoConfirmDom = top.$(html);
            _kendoConfirmDom.kendoWindow(defaultOption);
            _kendoConfirm = _kendoConfirmDom.data("kendoWindow");
            _kendoConfirm.center();
            _kendoConfirm.open();
            _kendoConfirmDom.find("#confirmOk").click(function () { defaultOption.ok.callback(fun, _kendoConfirm); });
            _kendoConfirmDom.find("#confirmCancel").click(function () { defaultOption.cancel.callback(funno, _kendoConfirm); });

        }
})(kendo);

(function ($) {
    $.getUrlParam = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return unescape(r[2]); return null;
    }
})(jQuery);

 

/***************************************V4.0兼容以前***********************************************/

function getToken() {
    return $.cookie("XFWLSUID");
}
function getFactUrl(url) {
    var token = $.cookie("XFWLSUID");
    if (token == undefined) {
        token = "";
    }
    url = url.replaceAll("{{token}}", token);
    return url;
}
 
function TOPAjax40(options) {
   
    if (options.async == undefined) options.async = true;
    if (!options.timeout) options.timeout = 120000;
    if (options.contentType == undefined) options.contentType = "application/x-www-form-urlencoded";
    top.$.ajax({
        url: options.url,
        type: "POST",
        dataType: 'json',
        async: options.async,
        data: options.data,
        contentType: options.contentType,
        success: function (r) {
            if (r.C == "10"   ) {
                ReLogin();
            }
            else {
                options.success(r);
            }
        },
        timeout: options.timeout,
        cache: false,
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            if (options.error) {
                options.error(textStatus + " " + errorThrown );
            }  
        }
    });
}


KDDataSourceOptions40 = {
    transport: {
        read: {
            dataType: "json",
            type: "POST",
            cache: false
        },
        update: {
            dataType: "json",
            type: "POST",
            cache: false
        },
        destroy: {
            dataType: "json",
            type: "POST",
            cache: false
        },
        create: {
            dataType: "json",
            type: "POST",
            cache: false
        },
        "prefix": ""
    },
    type: "aspnetmvc-ajax",
    error: function () { },
    batch: "false",
    serverPaging: true,
    serverFiltering: true,
    serverSorting: true,
    pageSize: 10,
    page: 1,
    schema: {
        data: "D1",
        total: "D2",
        errors: "M"
    }
}
KDDSWithRowNOOptions40 = $.extend(true, {}, KDDataSourceOptions40, {
    requestEnd: function (e) {  
        if (e.response.Errors || e.response.M) return; 
        for (var i = 0; i < e.response.D1.length; i++) {
            e.response.D1[i].RowNO = (e.sender.page() - 1) * e.sender.pageSize() + 1 + i;
        }
    }
});
function DevicesDetail50(id) { 
    var opt = myGetTop().GetFullWH();
    var w = Math.min(opt.w - 50, 1200);
    var h = Math.min(opt.h - 50, 670);
    var url = "/dw5/devicesex5/Detail?ID=" + id;
    myWindowOpen({
        title: "设施" + '详情'
        , url: url
        , width: w
        , height: h
        , close: function (win) {

        }
    });
}
/**
 * 设备详情Url
 * @param {any} id  devices.ID1
 * @param {any} gwtype  设备类型  00  未联网  10  消防主机。。。。。。。
 */
function DeviceDetailUrl40(id, gwtype) {
    var url = "";
    var name = "监控设备详情";
    switch (gwtype) {
        case "00":
            url = "/org/devices/detail1?ID=" + id;
            name = "非联网设备详情";
            break;
        case "10":
        case "30":
            url = "/org/devicesex/kzqdetail?ID=" + id
            break;
        case "20":
            url = "/org/devicesex/tcqdetail?ID=" + id
            break;
        case "11":
        case "31":
            url = "/org/devices/detail0?ID=" + id
            break;
        case "50":
            name = "设施详情";
            break;
    };
    return {url:url,name:name};
}
/**
 * 设备详情
 * @param {any} id  devices.ID1
 * @param {any} gwtype  设备类型  00  未联网  10  消防主机。。。。。。。
 */
function DeviceDetail40(id, gwtype) {
    var opt = top.GetFullWH();
    var h = Math.min(opt.h - 50, 650);
    switch (gwtype) {
        case "00":
            TOPkendoWindowIframeOpen({
                title: '非联网设备详情'
                , url: "/org/devices/detail1?ID=" + id
                , isMax: false
                , width: 1200
                , height: h
                , success: function (m) {
                }
                , close: function (win) {
                }
            });
            break;
        case "10":
        case "30":
            TOPkendoWindowIframeOpen({
                title: '消防主机详情'
                , url: "/org/devicesex/kzqdetail?ID=" + id
                , isMax: false
                , width: 1200
                , height: h
                , success: function (m) {
                }
                , close: function (win) {
                }
            });
            break;
        case "20":
            TOPkendoWindowIframeOpen({
                title: '独立式设备详情'
                , url: "/org/devicesex/tcqdetail?ID=" + id
                , isMax: false
                , width: 1200
                , height: h
                , success: function (m) {
                }
                , close: function (win) {
                }
            });
            break;
        case "11":
        case "31":
            TOPkendoWindowIframeOpen({
                title: '监控设备详情'
                , url: "/org/devices/detail0?ID=" + id
                , isMax: false
                , width: 1200
                , height: h
                , success: function (m) {
                }
                , close: function (win) {
                }
            });
            break;
        case "71"://视频通道
            {
                TOPkendoWindowIframeOpen({
                    title: "视频信息",
                    url: "/org/dvsdevice" + "/WatchChannel/" + id,
                    width: 1000,
                    height: 650,
                    isMaxH: false
                });
            }
            break;
    };
}
/**
 * 趋势图
 * @param {any} DEV_GW_ID
 * @param {any} Channel
 * @param {any} SubChannel  
 * @param {any} Name 类型  温度1 、A相电流
 * @param {any} GW 网关号
 */
function DeviceQST40(DEV_GW_ID, Channel, SubChannel, Name, GW) {
    TOPkendoWindowIframeOpen({
        title: '趋势图'
        , url: "/org/devicesexmll/qst/detail0?DEV_GW_ID=" + DEV_GW_ID + "&GW=" + GW + "&channel=" + Channel + "&subChannel=" + SubChannel + "&Name=" + Name
        , isMax: false
        , width: 1000
        , height: 550
        , success: function (m) {
        }
        , close: function (win) {
        }
    });
}

/*
 * 事件详情
 * @param {any}       ID:编号，EventName:类型，title:标题
 *  
 */
function EventDetail40(opt) {
    var url = "/org/eventinfoex/Detail/" + opt.id  ;
    if (!opt.title) {
        switch (opt.eventname) {
            case "火警":
                opt.title = "火警详情及处理";
                break;
            case "故障":
                opt.title = "故障详情";
                break;
            case "事件":
                opt.title = "事件详情";
                break;
        }
    } 
    TOPkendoWindowIframeOpen({
        title: opt.title
        , url: url
        , isMax: true
        , success: function (r) {
            if (opt.success) {
                opt.success(r);
            }
        },
        close: function (r) {
            if (opt.close) {
                opt.close(r);
            }
        }
    }); 
}

/*
 * 故障处理
 * @param {any}       id:编号，eventname:类型，title:标题
 *  
 */
function EventGZDeal40(opt) {
    var url = "/org/eventinfoex/GZDeal/" + opt.id;
    if (!opt.title) {
        opt.title = opt.eventname+"处理";
    }
    TOPkendoWindowIframeOpen({
        title: opt.title
        , url: url
        , isMax: true
        , success: function (r) {
            if (opt.success) {
                opt.success(r);
            }
        },
        close: function (r) {
            if (opt.close) {
                opt.close(r);
            }
        }
    });
}


/*
 * 故障批量处理
 * @param {any}       ids:编号，eventname:类型，title:标题
 *  
 */
function EventGZBatchDeal40(opt) {
    var url = "/org/eventinfoex/GZBatchDeal?eventname=" + encodeURIComponent(opt.eventname);
    if (!opt.title) {
        opt.title = opt.eventname +"批量处理";
    }
    TOPkendoWindowIframeOpen({
        title: opt.title
        , url: url
        ,width: 500
        ,height: 300
        , onload: function (win) {
            win.SetIds(opt.ids);
        }
        , success: function (r) {
            if (opt.success) {
                opt.success(r);
            }
        },
        close: function (r) {
            if (opt.close) {
                opt.close(r);
            }
        }
    });
}




/*
 * 故障处理
 * @param {any}       id:编号，eventname:类型，title:标题
 *  
 */
function EventHJDeal40(opt) {
    var url = "/org/eventinfoex/HJDeal/" + opt.id;
    if (!opt.title) {
        opt.title = "警情处理";
    }
    TOPkendoWindowIframeOpen({
        title: opt.title
        , url: url
        , isMax: true
        , success: function (r) {
            if (opt.success) {
                opt.success(r);
            }
        },
        close: function (r) {
            if (opt.close) {
                opt.close(r);
            }
        }
    });
}


/*
 * 故障批量处理
 * @param {any}       ids:编号，eventname:类型，title:标题
 *  
 */
function EventHJBatchDeal40(opt) {
    var url = "/org/eventinfoex/HJBatchDeal/";
    if (!opt.title) {
        opt.title = "故障批量处理";
    }
    TOPkendoWindowIframeOpen({
        title: opt.title
        , url: url
        , width: 500
        , height: 300
        , onload: function (win) {
            win.SetIds(opt.ids);
        }
        , success: function (r) {
            if (opt.success) {
                opt.success(r);
            }
        },
        close: function (r) {
            if (opt.close) {
                opt.close(r);
            }
        }
    });
}
/***************************************V5.0***************************************************/
var IsV50 = true;
/**
 * 获取V5最顶层
 * @param {any} win
 */
function myGetTop(win) {
    if (!win) {
        win = window;
    }
    //特殊处理 API全屏幕
    if (win.IsFullScreen  ) {  
        return win;
    }
    if (win.parent) {
        if (win == win.parent) {
            return win;
        }
    }
    else {
        return win;
    }
    

    if (win.IsV50 && win.parent&& win.parent.IsV50) {
        return myGetTop(win.parent);
    }
    else {
        return win;
    }
}
function myAjax(options) {
    if (options.win == undefined) {
        options.win = myGetTop();
    }
    if (options.async == undefined) options.async = true;
    if (!options.timeout) options.timeout = 30000;
    if (options.contentType == undefined) options.contentType = "application/json";
    if (options.type == undefined) options.type = "POST";
    if (options.contentType == "application/json") {
        if (typeof (options.data) != "string") {
            options.data = JSON.stringify(options.data);
        }
    }
    if (options.Alert == undefined) options.Alert = true;     
    var opt = {
        before: function () {
             kendo.ui.progress( $("body"), true);

        },
        after: function () {
            kendo.ui.progress($("body"), false);
        },
        timeout: options.timeout,
        contentType: options.contentType,
        type: options.type,
        dataType: 'json',
        async: options.async,
        cache: false,
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            opt2.after();
            if (options.Alert) {
                if (textStatus == "timeout") {
                    myAlert("请求超时");
                }
                else {
                    myAlert('错误.:' + textStatus + " " + errorThrown);
                }
            }
            else {
                opt2.err({ C: "-1", M: ""+textStatus + " " + errorThrown});
            }
             
        },
        err: function (r) {
            myAlert('错误:' + r.M);
        }
    }
    var opt2 = $.extend(true, {}, opt, options);
    opt2.success = function (r) {
        opt2.after();

        if (r.code == "" || r.C == "") {
            if (options.success) {
                options.success(r);
            }
        }
        else {
            opt2.err(r);
        }
    }
    opt2.before();
    options.win.$.ajax(opt2);
}


function kendoWindowIframeOpen(opt) {
    var win = window; 
    if (opt.content == null) {
        opt.content = opt.url;
    }
    var baseoption = {
        "ID": "1",
        "visible": false,
        "modal": true,
        "iframe": true,
        "draggable": true,
        "pinned": false,
        "animation": false,
        "title": "系统提示",
        "resizable": false,
        "content": "空",
        "width": 400,
        "height": 300,
        "actions": ["Refresh", "Close"]
    };
    if (opt.close) {
        opt.DOClose = opt.close;
        opt.close = undefined;
    }
    var option = $.extend({}, baseoption, opt);
    if (opt.left != undefined && opt.top != undefined) {
        option.position = { left: opt.left, top: opt.top };
    }
    if (opt.isMax) {
        var size = GetFullWH();
        option.height = size.h - 35;
        option.width = size.w - 10;
    }
    else if (opt.isMaxH) {
        var size = GetFullWH();
        option.height = size.h - 60;
    }
    else if (opt.isMaxW) {
        var size = GetFullWH();
        option.width = size.w - 60;
    }

    var id = Math.random().toString().substr(2);
    option.id = id;
    var w = win.$('<div id="' + id + '"/>').kendoWindow(option).data("kendoWindow");
    option.kendoWindow = w;

    kendo.ui.progress(win.$("#" + id), true);

    w.wrapper.find("iframe")[0].onload = w.wrapper.find("iframe")[0].onreadystatechange = function () {
        if (this.readyState && this.readyState != 'complete') return;
        else {
            kendo.ui.progress(win.$("#" + id), false);

        }
    }

    w.bind("refresh", function () {
        w.wrapper.find("iframe")[0].contentWindow.SelfClose = function (args) {
            if (args) {
                if (opt.success) {
                    try {
                        opt.success(args);
                    }
                    catch (Error) {
                    }
                }
            }
            if (typeof (win.winiframearr) != 'undefined') {
                if (win.winiframearr.length > 0) {
                    var topopt = win.winiframearr[win.winiframearr.length - 1];
                    if (topopt.id == option.id) { 
                        win.winiframearr.pop();
                    }
                } 
            }
            w.close();
        }
        if (option.onload) {
            option.onload(w.wrapper.find("iframe")[0].contentWindow);
        }
    });
    w.bind("close", function () {
        if (opt.DOClose) {
                try{
                    opt.DOClose(w.wrapper.find("iframe")[0].contentWindow);//初始化事件
                }
                catch (Error) {
                }
        }  
        if (typeof (win.winiframearr) != 'undefined') { 
            if (win.winiframearr.length > 0) { 
                var topopt = win.winiframearr[win.winiframearr.length - 1]; 
                if (topopt.id == option.id) {  
                    win.winiframearr.pop();
                }
            }
        }
        option.kendoWindow.destroy();
    });
    if (typeof (win.winiframearr) == 'undefined') {
        win.winiframearr = [];
    }
    win.winiframearr.push(option);
    if (option.position != undefined) {
        w.open();
    } else {
        w.center().open();
    }
    

}
function TOPkendoWindowIframeOpen(opt) {
    if (opt.win == undefined) {
        opt.win = myGetTop();
    } 
    opt.opener = window;
    opt.win.kendoWindowIframeOpen(opt);

}
/**
 * 打开新窗口
 * @param {any} opt
 */ 
function myWindowOpen(opt) {
    opt.opener = window;
    myGetTop().kendoWindowIframeOpen(opt);
}
function myWindowClose(r) {
    var win = myGetTop();
    var opt = win.winiframearr.pop();
    if (r) {
        if (opt.success) {
            try {
                opt.success(r);
            }
            catch (Error) {
            console.info(Error);
               // myAlert(Error)
               // win.winiframearr.push(opt);
                return;
            }

        }
    }
    opt.kendoWindow.close();
}
//{width:100,height:300}
function myWindowSetOptions(options) {
    var win = myGetTop();
    if (win.winiframearr && win.winiframearr.length > 0) {
        var opt = win.winiframearr[win.winiframearr.length-1];
        opt.kendoWindow.setOptions(options);
    } 
}
function myWindowAddLeft(w) {
    var win = myGetTop();
    if (win.winiframearr && win.winiframearr.length > 0) {
        var opt = win.winiframearr[win.winiframearr.length - 1];

        var left = opt.kendoWindow.options.position.left;
        var width = opt.kendoWindow.options.width;
        left = left - w;
        width = width + w;
        var s = { position: { left: left }, width: width };
        opt.kendoWindow.setOptions(s);  
    }
}
function myWindowAddRight(w) {
    var win = myGetTop();
    if (win.winiframearr && win.winiframearr.length > 0) {
        var opt = win.winiframearr[win.winiframearr.length - 1];

        var left = opt.kendoWindow.options.position.left;
        var width = opt.kendoWindow.options.width; 
        width = width + w;
        var s = {   width: width };
        opt.kendoWindow.setOptions(s);
    }
}

function getFooter() {
    var foot = $("#footer50");
    if (foot.length == 0) {
        var foot = $('<div id="footer50" style="display: none;"/>');
        $("body").append(foot);
    }
    var foot = $("#footer50");
    return foot;
}
function initAlertWin(opt) {
    var foot = getFooter();
    if (foot.find("#divalert").length == 0) {
        var divs = $('<div id="divalert">\n' +
            '            <div id="divalert_divMain" style="width:100%;height:100%;" class="flexcolumn">\n' +
            '\n' +
            '            <div id="divalert_divMid"  style="flex:1;overflow-y:auto;overflow-x:hidden;padding:10px;line-height:25px;"  >\n' +
            '            </div>\n' +
            '            <div id="divalert_divBottom" style="height:30px;border-top:1px dashed #143c75;text-align:right;padding-top: 10px;">\n' +
            '            <a id="divalert_ok" href="JavaScript:"  class="k-button k-primary"  style="width:80px;height:30px;" >\n' +
            '            <span class="k-icon k-i-success"></span>确定</a>'
        );
        foot.append(divs);

    }

    var win = foot.find("#divalert").kendoWindow({
        width: 400,
        height: 300,
        title: "提示",
        "resizable": false,
        visible: false,
        modal: true,
        actions: [
            "Close"
        ]
    }).data("kendoWindow")

    window.alertwin = win;

}
function myAlert(opt) {
    if (typeof (opt) == "string") {
        opt = {
            message: opt
        };
    }
    if (opt.win == undefined) {
        opt.win = myGetTop();
    }

    if (!opt.win.alertwin) {
        opt.win.initAlertWin();
    }
    var win = opt.win.alertwin;
    if (!opt.title) {
        opt.title = "系统提示";
    }
    if (!opt.w) {
        opt.w = 400;
    }
    if (!opt.h) {
        opt.h = 150;
    }
    opt.message = opt.message.replaceAll("\r\n", "<br/>");
    win.setOptions({
        width: opt.w,
        height: opt.h,
        title: opt.title
    });
    win.wrapper.find("#divalert_divMid").html(opt.message);
    win.wrapper.find("#divalert_ok").unbind("click");
    win.wrapper.find("#divalert_ok").bind("click", function () {
        if (opt.done) {
            opt.done();
        }
        win.close();
    });
    win.center().open();
}
function initPromptWin(opt) {


    var foot = getFooter();
    if (foot.find("#divprompt").length == 0) {
        var divs = $('<div id="divprompt"  >\n' +
            '    <div id="divprompt_divMain" style="width:100%;height:100%;" class="flexcolumn">\n' +
            '\n' +
            '        <div id="divprompt_divMid" style="flex:1;overflow:hidden;padding:10px;line-height:25px;">\n' +
            '            <div id="divprompt_divmsg"  ></div>\n' +
            '            <textarea id="divprompt_textarea" class="k-textbox" style="width:100%;height:90px;"></textarea>\n' +
            '            <input id="divprompt_input" class="k-textbox" style="width:100%;height:25px;"></input>\n' +
            '        </div>\n' +
            '        <div id="divprompt_divBottom" style="height:30px;border-top:1px solid #cccccc;text-align:right;padding-top: 5px;">\n' +
            '            <a id="divprompt_ok" href="JavaScript:" class="k-button k-primary" style="width:100px;">\n' +
            '                <span class="k-icon k-i-success"></span>确定</a>\n' +
            '            &nbsp;&nbsp;\n' +
            '            <a id="divprompt_cancel" href="JavaScript:" class="k-button" style="width:100px;">\n' +
            '                <span class="k-icon k-i-cancel"></span>取消</a>\n' +
            '        </div>\n' +
            '    </div>\n' +
            '</div>');
        foot.append(divs);

    }

    var win = foot.find("#divprompt").kendoWindow({
        width: 400,
        height: 300,
        title: "录入提示",
        "resizable": false,
        visible: false,
        modal: true,
        actions: [
            "Close"
        ]
    }).data("kendoWindow")

    window.promptwin = win;

}
function myPrompt(opt) {
    if (opt.win == undefined) {
        opt.win = myGetTop();
    }

    if (!opt.win.promptwin) {
        opt.win.initPromptWin();
    }
    var win = opt.win.promptwin;
    if (!opt.title) {
        opt.title = "录入提示";
    }

    if (!opt.w) {
        opt.w = 400;
    }
    if (!opt.h) {
        opt.h = 150;
        if (opt.IsMult) {
            opt.h = 200;
        }
    }
    if (!opt.Default) {
        opt.Default = "";
    }
    opt.message = opt.message.replaceAll("\r\n", "<br/>");
    win.setOptions({
        width: opt.w,
        height: opt.h,
        title: opt.title
    });
    if (opt.Prompt) {
        win.wrapper.find("#divprompt_divmsg").html(opt.Prompt);
    }
    else if (opt.message) {
        win.wrapper.find("#divprompt_divmsg").html(opt.message);
    }

    if (opt.IsMult) {
        win.wrapper.find("#divprompt_textarea").val(opt.Default)
        win.wrapper.find("#divprompt_textarea").show();
        win.wrapper.find("#divprompt_input").hide();
    }
    else {
        win.wrapper.find("#divprompt_input").val(opt.Default)
        win.wrapper.find("#divprompt_input").show();
        win.wrapper.find("#divprompt_textarea").hide();
    }

    win.wrapper.find("#divprompt_ok").unbind("click");
    win.wrapper.find("#divprompt_ok").bind("click", function () {
        var data = "";
        if (opt.IsMult) {
            data = win.wrapper.find("#divprompt_textarea").val();
        }
        else {
            data = win.wrapper.find("#divprompt_input").val();
        }
        if (opt.done) {
            opt.done(data);
        }
        win.close();
    });
    win.wrapper.find("#divprompt_cancel").unbind("click");
    win.wrapper.find("#divprompt_cancel").bind("click", function () {
        if (opt.fail) {
            opt.fail();
        }
        win.close();
    });

    win.center().open();
}
function initConfirmWin(opt) {
    var foot = getFooter();
    if (foot.find("#divconfirm").length == 0) {
        var divs = $('<div id="divconfirm">\n' +
            '            <div id="divconfirm_divMain" style="width:100%;height:100%;" class="flexcolumn">\n' +
            '\n' +
            '            <div id="divconfirm_divMid"  style="flex:1;overflow-y:auto;overflow-x:hidden;padding:10px;line-height:25px;"  >\n' +
            '            </div>\n' +
            '            <div id="divconfirm_divBottom" style="height:30px;border-top:1px solid #cccccc;text-align:right;padding-top: 5px;">\n' +
            '            <a id="divconfirm_ok" href="JavaScript:"  class="k-button "  style="width:80px;" >\n' +
            '            确定</a>\n' +
            '            &nbsp;&nbsp;\n' +
            '            <a id="divconfirm_cancel" href="JavaScript:" class="k-button k-cancel" style="width:80px;">\n' +
            '                </span>取消</a>\n' +
            '        </div>\n' +
            '    </div>\n' +
            '</div>');
        foot.append(divs);

    }

    var win = foot.find("#divconfirm").kendoWindow({
        width: 400,
        height: 300,
        title: "提示",
        "resizable": false,
        visible: false,
        modal: true,
        actions: [
            "Close"
        ]
    }).data("kendoWindow")

    window.confirmwin = win;

}
function myConfirm(opt) {
    if (opt.win == undefined) {
        opt.win = myGetTop();
    }
    if (!opt.win.confirmwin) {
        opt.win.initConfirmWin();
    }
    var win = opt.win.confirmwin;

    if (!opt.title) {
        opt.title = "确认";
    }
    if (!opt.w) {
        opt.w = 400;
    }
    if (!opt.h) {
        opt.h = 150;
    }
    win.setOptions({
        width: opt.w,
        height: opt.h,
        title: opt.title
    });
    win.wrapper.find("#divconfirm_divMid").html(opt.message);
    win.wrapper.find("#divconfirm_ok").unbind("click");
    win.wrapper.find("#divconfirm_ok").bind("click", function () {
        if (opt.done) {
            opt.done();
        }
        win.close();
    });
    win.wrapper.find("#divconfirm_cancel").unbind("click");
    win.wrapper.find("#divconfirm_cancel").bind("click", function () {
        if (opt.fail) {
            opt.fail();
        }
        win.close();
    });
    win.center().open();
}
//是否是弹出层
function IsTopPopWin() {
    var topwin = myGetTop();

    if (typeof (topwin.winiframearr) == 'undefined') {
        return false; 
    }
    if (topwin.winiframearr.length > 0) {
        var topopt = topwin.winiframearr[topwin.winiframearr.length - 1];
        if (typeof (topopt.kendoWindow) == 'undefined') {
            return false;
        }
        var w = topopt.kendoWindow;
        if (w.wrapper.find("iframe").length == 0) {
            return false;
        }
        var currwin = w.wrapper.find("iframe")[0].contentWindow;
        if (!currwin) {
            return false;
        }
        if (currwin == window) {
            return true;
        }  
        if (window.parent && currwin == window.parent) {
            return true;
        }  
        if (window.parent && window.parent.parent && currwin == window.parent.parent ) {
            return true;
        }  
    }
    return false;
}

//获取弹出层opener
function GetPopOpener() {
    var topwin = myGetTop();

    if (typeof (topwin.winiframearr) == 'undefined') {
        return null;
    }
    if (topwin.winiframearr.length == 0) {
        return null;
    }
    for (var i = topwin.winiframearr.length - 1; i >= 0; i--) {
        var topopt = topwin.winiframearr[i];
        if (typeof (topopt.kendoWindow) == 'undefined') {
            return null;
        }
        var w = topopt.kendoWindow;
        if (w.wrapper.find("iframe").length == 0) {
            return null;
        }
        var currwin = w.wrapper.find("iframe")[0].contentWindow;
        if (!currwin) {
            return null;
        }
        if (currwin == window) {
            return topopt.opener;
        }
    } 
    return null;
}
//是否有弹出层
function HavePopWin() {
    var topwin = myGetTop();

    if (typeof (topwin.winiframearr) == 'undefined') {
        return false;
    }
    if (topwin.winiframearr.length > 0) {  
       return true;      
    }
    return false;
}

function isFullscreenEnabled() {
    return (
        document.fullscreenEnabled ||
        document.mozFullScreenEnabled ||
        document.webkitFullscreenEnabled ||
        document.msFullscreenEnabled
    );
} 
function requestFullScreen( ) {
    
    var elem = document.body;
    if (elem.webkitRequestFullScreen) {
        elem.webkitRequestFullScreen();
        
    } else if (elem.mozRequestFullScreen) {
        elem.mozRequestFullScreen();
        
    } else if (elem.requestFullScreen) {
        elem.requestFullscreen();
        
    } else {
        alert("浏览器不支持全屏API或已被禁用")
    }
}
function exitFullscreen() {
    var elem = document;
    if (elem.webkitCancelFullScreen) {
        elem.webkitCancelFullScreen();
         
    } else if (elem.mozCancelFullScreen) {
        elem.mozCancelFullScreen();
        
    } else if (elem.cancelFullScreen) {
        elem.cancelFullScreen();
        
    } else if (elem.exitFullscreen) {
        elem.exitFullscreen();
        
    } else {
        alert("浏览器不支持全屏API或已被禁用")
    }
} 
//API 全屏，F11有问题
function isFullscreen() {
    var b = document.fullscreenElement ||
        document.msFullscreenElement ||
        document.mozFullScreenElement ||
        document.webkitFullscreenElement;
    if (b) {
        return true;
    }
    return false; 
} 
//全屏判断就得考虑是否是按了F11键全屏,不能有滚动条
function isFullscreenForNoScroll() {
    var explorer = window.navigator.userAgent.toLowerCase();
    if (explorer.indexOf('chrome') > 0) {//webkit
        var ix  = Math.abs(document.body.scrollHeight - window.screen.height);
        var iy = Math.abs(document.body.scrollWidth - window.screen.width); 
        if (ix<10&&iy<10) {
            return true;
        } else {
            return false;
        }
    } else {//IE 9+  fireFox
        var ix = Math.abs(window.outerHeight - window.screen.height);
        var iy = Math.abs(window.outerWidth - window.screen.width);
        if (ix < 10 && iy < 10) {
            return true;
        } else {
            return false;
        } 
    }
} 
/**
 * 放大图片，后面考虑加入  滚动放大、关闭功能
 * @param {any} obj img 对象
 *  
 */
function BigImg40(obj) {
    var url = $(obj).attr("url");
    if (!url) {
        url = $(obj).attr("src");
    }

    var img = new Image()
    img.onload = function () {
        BigImg40Show(obj, url, this.width, this.height);
    }
    img.src = url;

}
function BigImg40Show(obj, url, w, h) {
    var win = myGetTop();
    var rate = 1.0 * w / h;
    var fullw = screen.availWidth;
    var fullh = screen.availHeight;

    if (rate > fullw / fullh) {
        h = parseInt(1.0 * w / fullw * h);
        w = fullw;

    } else {
        w = parseInt(1.0 * fullh / h * w);
        h = fullh;

    }

    var ileft = (fullw - w) / 2;
    var itop = (fullh - h) / 2;
    var zindex = win.GetMaxZ_index() + 2;
    if (win.$('#BigImg40Div').length == 0) {
        var s = '<div onclick="$(\'#BigImg40Div\').hide();")" id="BigImg40Div" style="position:absolute;z-index:' + zindex + ';width: ' + fullw + 'px;height:' + fullh + 'px;background-color:gray;opacity:0.98;">'
            + '<img id="BigImg40Img"  onclick="$(\'#BigImg40Div\').hide();")"'
            + ' src="' + url + '"'
            + ' style="position:absolute; width:' + w + 'px;height:' + h
            + 'px;left:' + ileft + 'px;top:' + itop + 'px;opacity:1"/>'
            + ' </div >';
        var first = win.$("body").prepend(s);
        $(obj).trigger("click");
    }
    else {
        win.$("#BigImg40Img").css({
            "width": "" + w + "px",
            "height": "" + h + "px",
            "left": "" + ileft + "px",
            "top": "" + itop + "px",

        });
        win.$("#BigImg40Img").attr("src", url);
        win.$("#BigImg40Div").css({
            "z-index": "" + zindex
        });
        win.$('#BigImg40Div').show();
    }
}

function BigImg(obj) {
    var url = $(obj).attr("url");
    var title = "图片";
    if (!url) {
        url = $(obj).attr("src");
        var a  = $(obj).attr("img-title");
        if (a) title = a;
    }
    
    myWindowOpen({
        title
        , url: "/sys/Image/ShowBigImg?url=" + escape(url)
        , isMax: true
        , success: function (r) {
        }
    });
}
//是否IE
function isIE() {
    if (!!window.ActiveXObject || "ActiveXObject" in window) {
        return true;
    } else {
        return false;
    }
}  
  
/***************************************V5.0***************************************************/

function ResumeSuAttr4() {
        
    myAjax({
        url: "/SYS5/User5API/SetAttr4",
        timeout: 3000,
        before: function () {

        },
        after: function () {

        },
        err: function (r) {
            
        },
    })
}